package controllers;

import java.util.List;

import models.User;

import org.apache.commons.mail.DefaultAuthenticator;
import org.apache.commons.mail.EmailException;
import org.apache.commons.mail.SimpleEmail;

import play.libs.Mail;

public class Security extends Secure.Security {
    
   public static boolean authentify(String username, String password) {
	   
	   if(User.find("byUsername", username.toLowerCase()).fetch().size() > 0)
	   {
		   User user = (User) User.find("byUsername", username.toLowerCase()).fetch().get(0);
		   return user != null && user.password.equals(password);
	   }
	   return false;
	   

	   
    } 
   
	public static void sendEmail(String email)
	{

		SimpleEmail Semail = new SimpleEmail();
		try {
			Semail.setHostName("smtp.gmail.com");
			Semail.setSmtpPort(465);
			Semail.setTLS(true);
			Semail.setFrom(email);
			//Semail.addTo("eng.sam.85@gmail.com");
			Semail.addTo(email);
			Semail.setAuthenticator(new DefaultAuthenticator("Michael.Ibraam", "sssss222"));
			Semail.setSubject("This is the subject");
			Semail.setMsg("Your password is ay 7aga kolo bynf3 delo2ty");
			
			
			

		//	Semail.setAuthenticator(new DefaultAuthenticator(notification.sender.username, notification.sender.password));
			//Semail.setFrom(notification.sender.email);
			//Semail.setSubject(notification.subject);
			//Semail.setMsg(notification.content);
			//Semail.addTo(notification.receiver.email);
			
			
			
			
		} catch (EmailException e) {
			e.printStackTrace();
		}
		Mail.send(Semail); 

	}
	
    
   
   
   
   
   
   
}
